package day11;

import java.util.concurrent.locks.ReentrantLock;

public class Homework1 {
    static int count = 0;
    ReentrantLock lock=new ReentrantLock(true);
    public void printA() {
        String name=Thread.currentThread().getName();
        lock.lock();
        if(count!=100){
            count++;
            System.out.println(name+"打印了:"+count);
        }
        lock.unlock();
    }
    public static void main(String[] args) {
        Homework1 h=new Homework1();
        new Thread(()->{
            if(count!=100){
                while (true){
                    h.printA();
                }
            }
        },"线程1").start();
        new Thread(()->{
            if(count!=100){
                while (true){
                    h.printA();
                }
            }
        },"线程2").start();
        new Thread(()->{
            if(count!=100){
                while (true){
                    h.printA();
                }
            }
        },"线程3").start();
    }
}
